#ifndef _DBSVR_HPP_20120610
#define _DBSVR_HPP_20120610

#include <ext/hash_map>

#include "singleton.hpp"
#include "queue.hpp"
#include "thread.hpp"
#include "connection.hpp"
#include "acceptor_manager.hpp"
#include "runner.hpp"
#include "basesvr.hpp"

#include "db_queue.hpp"

#include "cmd_parser.hpp"
#include "confsvr_cmd.hpp"
#include "processor.hpp"


using namespace mina;
using namespace cmd;
using namespace mina::thread;

typedef SSDBSvrRes DBSvrConf;

class DBSvr : public BaseSvr, public Singleton<DBSvr>
{
	public :
		friend class Singleton<DBSvr>;

	public :
		typedef ThreadPool<DBRequest, DBResponse, Queue> DBThreadPool;
		typedef AcceptorManager Reactor;

	public :
		virtual ~DBSvr() { finish(); }

		template <typename _Msg>
			int handle(Connection & conn, _Msg & msg)
			{
				assert(false);
				return 0;
			}

		// should implement those function
		virtual int impl_init();
		virtual int process();
		virtual int reload();
		virtual int finish();

		Reactor * reactor()               { return _reactor; }
		DBThreadPool * db_thread_pool()   { return _db_thread_pool; }

	public :
		Reactor         *  _reactor;
		DBThreadPool    *  _db_thread_pool;
		DBSvrConf          _conf;

		Processor<DBSvr>   _processor;
		CmdParser          _parser;
};

#endif

